package com.nftturbocollection.controller;

import com.nftturboapi.collection.model.CollectionVO;
import com.nftturboapi.collection.request.CollectionPageQueryRequest;
import com.nftturboapi.collection.service.CollectionFacadeService;
import com.nftturbobase.response.PageResponse;
import com.nftturbobase.response.SingleResponse;
import com.nftturboweb.util.MultiResultConvertor;
import com.nftturboweb.vo.MultiResult;
import com.nftturboweb.vo.Result;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("collection")
public class CollectionController {
    @Autowired
    private CollectionFacadeService collectionFacadeService;

    /**
     * 藏品列表
     *
     * @param
     * @return 结果
     */
    @GetMapping("/collectionList")
    public MultiResult<CollectionVO> collectionList(
            @RequestParam(defaultValue = "SUCCEED") @NotBlank String state,  // 默认值 "PUBLISHED"
            @RequestParam(required = false, defaultValue = "") String keyword, // 默认空字符串
            @RequestParam(defaultValue = "5") int pageSize,                   // 默认 10
            @RequestParam(defaultValue = "1") int currentPage                  // 默认第 1 页
    ) {
        CollectionPageQueryRequest collectionPageQueryRequest = new CollectionPageQueryRequest();
        collectionPageQueryRequest.setState(state);
        collectionPageQueryRequest.setKeyword(keyword);
        collectionPageQueryRequest.setCurrentPage(currentPage);
        collectionPageQueryRequest.setPageSize(pageSize);
        PageResponse<CollectionVO> pageResponse = collectionFacadeService.pageQuery(collectionPageQueryRequest);
        return MultiResultConvertor.convert(pageResponse);
    }

    /**
     * 藏品详情
     *
     * @param
     * @return 结果
     */
    @GetMapping("/collectionInfo")
    public Result<CollectionVO> collectionInfo(@NotBlank String collectionId) {
        SingleResponse<CollectionVO> singleResponse = collectionFacadeService.queryById(Long.valueOf(collectionId));
        return Result.success(singleResponse.getData());
    }


}